package com.ly.ocw.service.weixin;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ly.ocw.comm.MyPage;
import com.ly.ocw.entity.weixin.WeixinUserCard;
import com.ly.ocw.repository.weixin.WeixinUserCardDao;

/**
 * 
 * 
 * @author Peter
 */
// Spring Service Bean的标识.
@Component
public class WeixinUserCardService {

	private static Logger logger = LoggerFactory.getLogger(WeixinUserCardService.class);

	@Autowired
	private WeixinUserCardDao weixinUserCardDao;

	@Autowired
	private WeixinConf weixinConf;

	public WeixinUserCard getById(Long id) {
		return weixinUserCardDao.getById(id);
	}

	public List<WeixinUserCard> getAll() {
		return weixinUserCardDao.getAll();
	}

	/**
	 * 分页查询
	 * 
	 * @param overtime
	 * @param pageStart
	 * @param pageSize
	 * @return
	 */
	public MyPage<WeixinUserCard> searchPage(WeixinUserCard weixinUserCard, int currentPage, int pageSize) {
		MyPage<WeixinUserCard> myPage = new MyPage<WeixinUserCard>();

		Long count = weixinUserCardDao.searchCount(weixinUserCard);

		int pageStart = (currentPage - 1) < 0 ? 0 : (currentPage - 1) * pageSize;
		List<WeixinUserCard> list = weixinUserCardDao.searchPage(weixinUserCard, pageStart, pageSize);

		myPage.setCount(count);
		myPage.setContent(list);

		return myPage;
	}

	public void save(WeixinUserCard weixinUserCard) {
		weixinUserCard.setWeixinPublicId(weixinConf.getPublicId());
		weixinUserCardDao.save(weixinUserCard);
	}

	public void update(WeixinUserCard weixinUserCard) {
		weixinUserCardDao.update(weixinUserCard);
	}

	/**
	 * 软删除
	 */
	public void delete(Long id) {
		weixinUserCardDao.delete(id);
	}

	public WeixinUserCard getByOpenid(String openid) {
		return weixinUserCardDao.getByOpenid(openid);
	}

	public List<WeixinUserCard> getByCardId(String cardId) {
		return weixinUserCardDao.getByCardId(cardId);
	}

	public WeixinUserCard getByOpenidAndCardId(String openid, String cardId) {
		return weixinUserCardDao.getByOpenidAndCardId(openid,cardId);
	}
}
